package cn.tedu.charging.user.controller;

import cn.tedu.charging.common.pojo.param.ChargeParam;
import cn.tedu.charging.common.pojo.param.VehicleBindParam;
import cn.tedu.charging.common.pojo.vo.BalanceVO;
import cn.tedu.charging.common.pojo.vo.VehicleVO;
import cn.tedu.charging.common.protocol.JsonResult;
import cn.tedu.charging.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 定义所有和车主有关的接口 6
 * 登录
 * 查询余额
 * 充值
 * 查询车辆绑定
 * 绑定 解绑
 */
@RestController
public class UserController {
    @Autowired
    private UserService userService;

    // 小程序用户微信登录
    @GetMapping("/user/wx/login")
    public JsonResult<Integer> wxLogin(String nickName,String code){
        //调用业务层 获取当亲用户的userId(本地的,小程序的车主用户)
        Integer userId = userService.wxLogin(nickName,code);
        return JsonResult.ok(userId);
    }
    //查询余额
    @GetMapping("/user/balance/{userId}")
    public JsonResult<BalanceVO> myBalance(@PathVariable Integer userId){
        //控制层要什么 业务层就返回什么
        BalanceVO balanceVO = userService.myBalance(userId);
        return JsonResult.ok(balanceVO);
    }
    //给车主充值
    @PostMapping("/user/charge")
    public JsonResult<Void> charge(@RequestBody ChargeParam param){
        userService.charge(param);
        return JsonResult.ok(null);
    }
    //查询该用户正在使用绑定的车辆
    @GetMapping("/user/vehicle/binded/{userId}")
    public JsonResult<VehicleVO> bindedVehicle(@PathVariable Integer userId){
        VehicleVO vehicleVO = userService.bindedVehicle(userId);
        return JsonResult.ok(vehicleVO);
    }

    //用户绑定车辆
    @PostMapping("/user/vehicle/bind")
    public JsonResult<Void> bindVehicle(@RequestBody VehicleBindParam param){
        userService.bindVehicle(param);
        return JsonResult.ok(null);
    }
}
